package com.wochao.web.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wochao.model.entity.ViewAppointment;
import com.wochao.web.app.mapper.ViewAppointmentMapper;
import com.wochao.web.app.service.ApartmentInfoService;
import com.wochao.web.app.service.ViewAppointmentService;
import com.wochao.web.app.vo.apartment.ApartmentItemVo;
import com.wochao.web.app.vo.appointment.AppointmentDetailVo;
import com.wochao.web.app.vo.appointment.AppointmentItemVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {

    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;

    @Autowired
    private ApartmentInfoService apartmentInfoService;

    /**
     * 用户查询个人预约看房列表
     *
     * @param userId
     * @return
     */
    @Override
    public List<AppointmentItemVo> SelectRoomListByUserId(Long userId) {
        return viewAppointmentMapper.SelectRoomListByUserId(userId);
    }

    /**
     * 根据ID查询预约详情信息
     *
     * @param id
     * @return
     */
    @Override
    public AppointmentDetailVo getDetailById(Long id) {
        //查询预约看房信息
        ViewAppointment viewAppointment = viewAppointmentMapper.selectById(id);

        //查询公寓信息
        ApartmentItemVo apartmentItemVo = apartmentInfoService.selectApartmentItemVoById(viewAppointment.getApartmentId());

        //合并结果
        AppointmentDetailVo appointmentDetailVo = new AppointmentDetailVo();
        BeanUtils.copyProperties(viewAppointment,appointmentDetailVo);

        appointmentDetailVo.setApartmentItemVo(apartmentItemVo);

        return appointmentDetailVo;
    }
}




